package com.guanyong.services;

import com.guanyong.dao.IHistoryTodayDaoMapper;
import com.guanyong.model.HistoryTodayModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.HashMap;
import java.util.List;

/**
 * Created by mxk on 2017/6/6.
 */
@Service
public class HistoryTodayService {
    @Autowired
    IHistoryTodayDaoMapper iHistoryTodayDaoMapper;

    @Autowired
    ObjectClassTypeService objectClassTypeService;


    public HistoryTodayModel GetHistoryTodayModelById(Integer fid){

        return  iHistoryTodayDaoMapper.selectByPrimaryKey(fid);
    }

    public HistoryTodayModel GetHistoryByDate(String date,Integer classtype,String objectid){
        return iHistoryTodayDaoMapper.SelectByDateObjectId(date,classtype,objectid);
    }

    //获取历史的今天
    public HashMap<String,Object> GetHistoryTodayList(
            HistoryTodayModel historyTodayModel,
            Integer pno,
            Integer pagesize,
            Integer allcount){
        HashMap<String,Object> hashMap=new HashMap();
        if (allcount<0){
            Integer count=iHistoryTodayDaoMapper
                    .SelectHistoryTodayListCount(historyTodayModel);
            hashMap.put("count",count);
        }
        else {
            hashMap.put("count",allcount);
        }
        List<HistoryTodayModel> priceTagModelList
                =iHistoryTodayDaoMapper.SelectHistoryTodayList(historyTodayModel
                ,(pno-1)*pagesize,
                pagesize);

        for(HistoryTodayModel historyTodayModel1 : priceTagModelList){
            Object objectService=objectClassTypeService.GetObject(historyTodayModel1.getfClasstype(),
                    historyTodayModel1.getfObjectid());
            historyTodayModel1.setfObject(objectService);
        }
        hashMap.put("list",priceTagModelList);


        return hashMap;
    }

    public  Integer UpdateHistoryToday(HistoryTodayModel historyTodayModel){
        return iHistoryTodayDaoMapper.update(
                historyTodayModel
        );
    }

    public Integer AddHistoryToday(HistoryTodayModel historyTodayModel){
        return  iHistoryTodayDaoMapper.insert(historyTodayModel);
    }



}
